/*  1:   */ package org.jetbrains.io;
/*  2:   */ 
/*  3:   */

import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.ui.UIUtil;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.FullHttpRequest;
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.QueryStringDecoder;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import org.apache.sanselan.ImageFormat;
import org.apache.sanselan.ImageWriteException;
import org.apache.sanselan.Sanselan;
import org.jetbrains.ide.HttpRequestHandler;

import javax.swing.*;
import java.awt.image.BufferedImage;
import java.io.IOException;

/*  4:   */
/*  5:   */
/*  6:   */
/*  7:   */
/*  8:   */
/*  9:   */
/* 10:   */
/* 11:   */
/* 12:   */
/* 13:   */
/* 14:   */
/* 15:   */
/* 16:   */
/* 17:   */
/* 18:   */
/* 19:   */
/* 20:   */
/* 21:   */
/* 22:   */
/* 23:   */ 
/* 24:   */ @ChannelHandler.Sharable
/* 25:   */ final class DelegatingHttpRequestHandler
/* 26:   */   extends DelegatingHttpRequestHandlerBase
/* 27:   */ {
/* 28:40 */   private static final AttributeKey<HttpRequestHandler> a = AttributeKey.valueOf("DelegatingHttpRequestHandler.handler");
/* 29:   */   
/* 30:   */   protected boolean process(ChannelHandlerContext paramChannelHandlerContext, FullHttpRequest paramFullHttpRequest, QueryStringDecoder paramQueryStringDecoder)
/* 31:   */     throws IOException, ImageWriteException
/* 32:   */   {
/* 33:44 */     Attribute localAttribute = paramChannelHandlerContext.attr(a);
/* 34:45 */     HttpRequestHandler localHttpRequestHandler = (HttpRequestHandler)localAttribute.get();
/* 35:46 */     if (localHttpRequestHandler != null)
/* 36:   */     {
/* 37:47 */       if ((localHttpRequestHandler.isSupported(paramFullHttpRequest)) && (localHttpRequestHandler.process(paramQueryStringDecoder, paramFullHttpRequest, paramChannelHandlerContext))) {
/* 38:48 */         return true;
/* 39:   */       }
/* 40:51 */       localAttribute.set(null);
/* 41:   */     }
/* 42:   */     Object localObject2;
/* 43:54 */     for (localObject2 : (HttpRequestHandler[])HttpRequestHandler.EP_NAME.getExtensions()) {
/* 44:   */       try
/* 45:   */       {
/* 46:56 */         if ((((HttpRequestHandler)localObject2).isSupported(paramFullHttpRequest)) && (((HttpRequestHandler)localObject2).process(paramQueryStringDecoder, paramFullHttpRequest, paramChannelHandlerContext)))
/* 47:   */         {
/* 48:57 */           localAttribute.set(localObject2);
/* 49:58 */           return true;
/* 50:   */         }
/* 51:   */       }
/* 52:   */       catch (Throwable localThrowable)
/* 53:   */       {
/* 54:62 */         BuiltInServer.LOG.error(localThrowable);
/* 55:   */       }
/* 56:   */     }
/* 57:66 */     if (paramQueryStringDecoder.path().equals("/favicon.ico"))
/* 58:   */     {
/* 59:67 */       ??? = IconLoader.findIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl());
/* 60:68 */       if (??? != null)
/* 61:   */       {
/* 62:69 */         BufferedImage localBufferedImage = UIUtil.createImage(((Icon)???).getIconWidth(), ((Icon)???).getIconHeight(), 2);
/* 63:70 */         ((Icon)???).paintIcon(null, localBufferedImage.getGraphics(), 0, 0);
/* 64:71 */         byte[] arrayOfByte = Sanselan.writeImageToBytes(localBufferedImage, ImageFormat.IMAGE_FORMAT_ICO, null);
/* 65:72 */         localObject2 = Responses.response(FileResponses.getContentType(paramQueryStringDecoder.path()), Unpooled.wrappedBuffer(arrayOfByte));
/* 66:73 */         Responses.addNoCache((HttpResponse)localObject2);
/* 67:74 */         Responses.send((HttpResponse)localObject2, paramChannelHandlerContext.channel(), paramFullHttpRequest);
/* 68:75 */         return true;
/* 69:   */       }
/* 70:   */     }
/* 71:79 */     return false;
/* 72:   */   }
/* 73:   */   
/* 74:   */   public void exceptionCaught(ChannelHandlerContext paramChannelHandlerContext, Throwable paramThrowable)
/* 75:   */     throws Exception
/* 76:   */   {
/* 77:84 */     super.exceptionCaught(paramChannelHandlerContext, paramThrowable);
/* 78:   */     
/* 79:86 */     paramChannelHandlerContext.attr(a).remove();
/* 80:   */   }
/* 81:   */ }



/* Location:           E:\idea\

 * Qualified Name:     org.jetbrains.io.DelegatingHttpRequestHandler

 * JD-Core Version:    0.7.0.1

 */